﻿using SuperJoe.Framework.Core.Exceptions;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using WWX.Dto;
using WWX.Model;

namespace WWX.Admin.Web.Models
{
    public class OrderVM
    {
        public string Id { get; set; }

        public string Account { get; set; }

        public string ProductInfo { get; set; }

        public string LogisticsInfo { get; set; }

        public decimal? PurchasePrice { get; set; }

        public decimal? SalePrice { get; set; }

        public OrderStatus? Status { get; set; }

        public string Remark { get; set; }

        public DateTime? Date { get; set; }

        private void Validate()
        {

            if (Id.IsNullOrWhiteSpace() && Account.IsNullOrWhiteSpace())
            {
                ThrowHelper.ThrowFriendlyException("请输入会员账号");
            }

            if (Status == null)
            {
                ThrowHelper.ThrowFriendlyException("请输入订单状态");
            }

            if (SalePrice == null)
            {
                ThrowHelper.ThrowFriendlyException("请输入订单售价");
            }

            if (Date == null)
            {
                ThrowHelper.ThrowFriendlyException("请输入订单时间");
            }
        }

        public OrderAdminSaveDto ToOrderSaveDto()
        {
            Validate();

            return new OrderAdminSaveDto()
            {
                Id = this.Id,
                Account = this.Account,
                ProductInfo = this.ProductInfo,
                LogisticsInfo = this.LogisticsInfo,
                PurchasePrice = this.PurchasePrice,
                SalePrice = this.SalePrice.Value,
                Status = this.Status.Value,
                Remark = this.Remark,
                Date = this.Date.Value
            };
        }
    }
}